package com.franklin.ideaplugin.easytesting.ui.execute;

import com.franklin.ideaplugin.api.ui.IBaseComponent;
import com.intellij.psi.PsiParameter;
import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.swing.*;

/**
 * @author Ye Junhui
 * @since 2023/7/2 17:53
 */
@Getter
@AllArgsConstructor
public abstract class ParameterTextComponent implements IBaseComponent {

    /**
     * 真正的组件
     */
    private final JComponent component;

    @Override
    public final JComponent getMainPanel() {
        return this.component;
    }

    /**
     * 文本内容
     * @return
     */
    public abstract String getText();

    /**
     * 获取参数类型
     * @param psiParameter
     * @return
     */
    public String getTypeStr(PsiParameter psiParameter){
        String typeStr = psiParameter.getType().getCanonicalText();
        if (typeStr.contains("<")) {
            int indexL = typeStr.indexOf("<");
            typeStr = typeStr.substring(0, indexL);
        }
        return typeStr;
    }

}
